package com.svconnect.util;


public class Log {

	public static final String TAG = "[WCFSupport] ";
	private static final LogLevel[] LEVELS = { LogLevel.None, LogLevel.Error, LogLevel.Info, LogLevel.Verbose };
	
	private static LogLevel level = LogLevel.None;
	

	public static void i(String info) {
		if (isOn(LogLevel.Info)) {
			System.out.println(String.format("%s%s", TAG, info));
		}
	}
	
	public static void v(String info) {
		if (isOn(LogLevel.Verbose)) {
			System.out.println(String.format("%s%s", TAG, info));
		}
	}

	public static void e(Exception ex) {
		if (isOn(LogLevel.Error)) {
			System.err.println(String.format("%s%s", TAG, ex.getMessage()));
			ex.printStackTrace(System.err);
		}
	}
	
	public static void e(String error, Exception ex) {
		if (isOn(LogLevel.Error)) {
			System.err.println(String.format("%s%s", TAG, error));
			ex.printStackTrace(System.err);
		}
	}
	
	public static LogLevel getLevel() {
		return level;
	}

	public static void setLevel(LogLevel level) {
		Log.level = level;
	}	
	
	private static boolean isOn(LogLevel selectedLvl) {
		for(int i=0; i<LEVELS.length; i++) {
			if (LEVELS[i].equals(selectedLvl)) return true;
			if (LEVELS[i].equals(level)) return false;
		}
		return false;
	}
	
	
}
